const format = (transform) => {
  const date = new Date(transform);
  const Y = date.getFullYear() + '-';
  const M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
  const D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' ';
  const h = date.getHours() + ':';
  const m = date.getMinutes() + ':';
  const s = date.getSeconds();

  return (Y + M + D);
}

const todayTime = new Date().getTime(); // 当前毫秒
const oneDayTime = 1000 * 60 * 60 * 24; // 一天时间

const makeTime = []

for (let i = 0; i < 7; i++) {
  const getFormat = format(todayTime + oneDayTime * i);
  const subTime = getFormat.split('-');

  makeTime.push({
    label: `${subTime[1]}-${subTime[2]}08:00-12:00`,
    startTime: getFormat + '08:00:00',
    endTime: getFormat + '12:00:00',
    value: i
  })

  makeTime.push({
    label: `${subTime[1]}-${subTime[2]}13:00-16:00`,
    startTime: getFormat + '13:00:00',
    endTime: getFormat + '16:00:00',
    value: 100 + i
  })
}

const getNewMakeTime = () => {
  const nowDate = parseInt(new Date().getHours());

  let newArr = [];

  switch (nowDate <= 12) {
    case true:
      newArr = makeTime.slice(1, makeTime.length);
      break;
    case false:
      newArr = makeTime.slice(2, makeTime.length);
      break;
  }

  newArr.map((item, index) => { // 重置value
    item.value = index
  })

  return newArr;
}

const newMakeTime = getNewMakeTime()

export default newMakeTime